<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ include file="/parameter.jsp" %>
<%@page isELIgnored="false"%>
<!DOCTYPE>
<html>
<head>
<TITLE>论坛</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<Meta http-equiv="Pragma" Content="No-cach">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> 
<META HTTP-EQUIV="Expires" CONTENT="0"> 
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="${pageContext.request.contextPath}/js/validator.js"></script>
<script language="javascript">
var state = 1;
function particularView(){
	if(state == 1){
		particular.style.display = "block";
		state = 0;
	}else{
		particular.style.display = "none";
		state = 1;
	}
}

function checkUser(){
	var name = registerForm.username.value;
	if(name != null && name != ""){
	document.frames["hidden1"].location = "commonAction.do?method=CheckUsername&username=" + registerForm.username.value;
	}else{
		alert("请先输入用户名!");
		return false;
	}
}

function toSubmit(){
	if(registerForm.username.value == ''){
		alert("用户名不能是空！");
		registerForm.username.focus();
		return false;
	}else if(registerForm.password.value == ''){
		alert("密码不能是空！");
		registerForm.password.value = '';
		registerForm.password.focus();
		return false;
	}else if(registerForm.repwd.value == ''){
		alert("确认密码不能是空！");
		registerForm.repwd.value = '';
		registerForm.repwd.focus();
		return false;
	}else if(registerForm.password.value != registerForm.repwd.value){
		alert("您输入的密码不一致！请重新输入！");
		registerForm.password.value = '';
		registerForm.repwd.value = '';
		registerForm.password.focus();
		return false;
	}else if(registerForm.inputrand.value == ''){
		alert("认证码不能是空！");
		registerForm.inputrand.value = '';
		registerForm.inputrand.focus();
	}else if(Validator.Validate(document.forms["registerForm"], 3)){
		return registerForm.submit();
	}
}

function root(box){
	if(box.checked == true){
		document.getElementById("mail").value = "true";
	}else{
		document.getElementById("mail").value = "false";
	}
}
    
  function refresh(obj){     
  	obj.src="image.jsp?id="+Math.random();     
  }     

</script>
</HEAD>
<body>
<jsp:include page="inc/header.jsp"/>
		<header class="entry-header">
			<h1 class="entry-title">
				<span>论坛首页<div id="searchbar">
				<form name="form3" method="post" action="commonAction.do?method=SearchTopic">
					<input type="text" id="keywords" name="keywords" title="搜索"><button onClick="search();">搜索</button>
				</form>
				</div></span>
			</h1>
		</header>
		
		<div id="maindiv">
			<div id="nav">
			<c:choose>
				<c:when test="${sessionScope.user == null}">
					<div>
						<form name="form1" method="post" action="commonAction.do?method=UserLogin">
						账号：<input type="text" name="username"> 密码：<input type="password" name="password"> 
						<button onClick="loginsubmit();">登陆</button> <a href="commonAction.do?method=toRegister">注册新账号</a>
						</form>
					</div>
				</c:when>
				<c:otherwise>
					<div>
					&nbsp;&nbsp;<c:choose><c:when test="${sessionScope.user.nickname != ''}">${sessionScope.user.nickname}</c:when><c:otherwise>${sessionScope.user.username}</c:otherwise></c:choose>&nbsp;你好！<a
							href="commonAction.do?method=Logout">注销</a>&nbsp;|&nbsp;<a
							href="commonAction.do?method=EditUserInfo&uid=${sessionScope.user.id}">修改个人信息</a>&nbsp;|&nbsp;<a
							href="commonAction.do?method=EditUserPwd&uid=${sessionScope.user.id}">修改密码</a>
					</div>
				</c:otherwise>
			</c:choose>
				<a href="./" title="首页">首页</a>
				<span>&gt;</span>
				<a href="###">注册</a>
			</div>
			
			
			
			<div id="board">
				<div class="bm">
					<div id="post_r">
						<div class="bm_h"><h2>注册新用户</h2></div>
						<div class="replay_b">
							<iframe id="hidden1" name="checkusername" allowtransparency="false" frameborder="0" style="height:0;width:0"></iframe>
							<form name="registerForm" id="registerForm" method="post" action="commonAction.do?method=UserRegister" enctype="multipart/form-data" onSubmit="return Validator.Validate(this, 3)">
								<!--<logic:notEmpty name="info">
									<div class="msg">
										<bean:write name="info"/>
									</div>
								</logic:notEmpty>-->
                                <div class="msg">
                                	<span class="error cl"><div id="info"></div><span>
								</div>
								<div class="frm_row">
									<label>用户名: </label><input type="text" name="username" size="20" maxlength="20" value="" title="请填写用户名！" onBlur="checkUser();"datatype="Require" msg="必须填写" /> *不能有空格，可以是中文，长度在 6 字节以上
								</div>
								<div class="frm_row">
									<label>密码: </label><input type="password" name="password" size="20" maxlength="20" value="" title="请输入密码！" datatype="Require" msg="必须填写"/> *英文字母或数字等不少于6位
								</div>
								<div class="frm_row">
									<label>确认密码: </label><input type="password"  name="repwd" size="20" maxlength="20" value="" title="请确认密码！" datatype="Require" msg="必须填写"/>
								</div>
								<div class="frm_row">
									<label>验证码: </label><input type="text" name="inputrand" size="20" maxlength="4" value="" title="请输入认证码！" datatype="Require" msg="必须填写"/><img border=0 src="image.jsp" align="absMiddle" onClick="refresh(this)" /> ← 点击换一张
								</div>
								
								<div class="frm_row">
									<div onClick="particularView();"><a href="###">填写详细资料</a></div>
								</div>
								<div id="particular" style="display:none;">
									<div class="frm_row">
										<label>邮件地址: </label><input type="text" name="email" size="50" maxlength="50" value="" title="请填写邮件地址！" /> *经常使用的邮箱地址
									</div>
									<div class="frm_row">
										<label>昵称: </label><input type="text" name="nickname" size="20" maxlength="20" value="" title="请填写昵称！" />
									</div>
									<div class="frm_row">
										<label>性别: </label><select name="sex" onChange="">
											<option value="保密">保密</option>
											<option value="帅哥">帅哥</option>
											<option value="美女">美女</option>
										</select>
									</div>
									<div class="frm_row">
										<label>生日: </label>
										<select name="year" onChange="changeDate();"><!--注意:考虑到润年的关系,这里也要加上onchange事件-->
										<%
										for(int i=1940;i<2100;i++){
										   out.print("<option value=\""+i+"\">"+i+"</option>");
										}
										%>
										</select>年
										<select name="month" onChange="changeDate();">
										<%
										for(int i=1;i<13;i++){
										   out.print("<option value=\""+i+"\">"+i+"</option>");
										}
										%>
										</select>月
										<select name="day">
										</select>日
									</div>
									<!--<div class="frm_row">
										<label>自定义头像: </label><input type="file" name="portrait" size="50" class="input2" alt="用户上传头像！" /> *用户可以上传自己喜爱的图片作为头像。
									</div>-->
								</div>
								<div class="frm_row">
									<button onClick="toSubmit();"> 提交注册 </button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			
			
		</div>

<jsp:include page="inc/footer.jsp"/>
</body>
<script language="javascript">
function changeDate(){
  var days = getMonthDays(document.registerForm.year.value,document.registerForm.month.value); //取得当前月应该有多少天
  var obj = document.registerForm.day;  //取得日期Select容器
  var lastValue = obj.value;  //记录用户选择的值
  if(lastValue*1 > days)lastValue = days;
  if(!lastValue)lastValue=1;
  while(obj.options.length>0) //清空日期选择框
obj.options.remove(0);
  for (var i=1; i<=days; i++)  //添加日期选项
obj.options.add(new Option(i,i));
  obj.value = lastValue;  //恢复用户选择的值
}

//获取指定月份的天数
function getMonthDays(year,month)
{
var d = new Date(year,month-1,1);
var returnValue = 0;
for(;d.getMonth()==month-1;d.setTime(d.getTime()+86400000))returnValue++;
	return returnValue;
}
changeDate(); //初始化日期选择框
</script>
</HTML>
